package whu.hami.tea.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import whu.hami.tea.R;
import whu.hami.tea.TeaApplication;

/**
 * Created by pendragon on 17-5-27.
 */

public class SplashActivity extends AppCompatActivity {

    private final MyHandler handler = new MyHandler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                SharedPreferences sp = ((TeaApplication) getApplication()).getSharedPreferences();

                Intent intent;
                if (sp.getString("user", "").equals("")){
                    intent = new Intent(SplashActivity.this, LoginActivity.class);
                } else
                    intent = new Intent(SplashActivity.this, MainActivity.class);

                startActivity(intent);
                finish();
            }
        }, 3000);
    }

    private static class MyHandler extends Handler {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    }

    @Override
    public void onBackPressed() {
        finish();
    }
}
